//
//  NetworkRequest.m
//  苏州银行
//
//  Created by rimi on 15/8/20.
//  Copyright (c) 2015年 IOS. All rights reserved.
//

#import "NetworkRequest.h"
#import "AFNetworking.h"
#import "Config.h"
@implementation NetworkRequest

+(void)POST:(NSString *)url parameters:(NSDictionary *)parameters success:(void(^)(id respondseObject))success failure:(void (^)(NSError *error))failure
{
    NSString *completeURL = [NSString stringWithFormat:@"%@%@",BASEURL,url];
    //初始化网络请求
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //配置网络请求超市时间
    manager.requestSerializer.timeoutInterval = 10;
    //设置MIME类型
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html", nil];
    //把字典参数转化为JSON Data类型
    NSData *parametersData = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:nil];
    //把Data转换为字符串
    NSString *parametersString = [[NSString alloc]initWithData:parametersData encoding:NSUTF8StringEncoding];
    //把字符串包装到字典里面，形成最终参数
    NSDictionary *parametersDic = @{@"paramJson":parametersString};
    
    //发起网络请求
    [manager POST:completeURL parameters:parametersDic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            success(responseObject);
            
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}





@end
